import type { FunctionOutputDtoSimple } from '@/api/authorization/admin/function/model';
import type { RoleOutputDtoSimple } from '@/api/identity/admin/role/model';

import type { ErrorMessageMode, PageData } from '#/request';

import { request } from '@/utils/request/axios';

import { PageRequest } from '#/request';

/** 管理-角色功能枚举 */
export enum Api {
  /** 读取角色 */
  ReadRoles = '/api/admin/roleFunction/readRoles',
  /** 读取角色功能 */
  ReadFunctions = '/api/admin/roleFunction/readFunctions',
}

// #region 读取角色信息
/**
 * 读取角色信息
 * @param params 分页请求
 * @param mode 错误消息模型
 */
export function readRoles(params: PageRequest, mode: ErrorMessageMode = 'message') {
  return request.post<PageData<RoleOutputDtoSimple>>(
    {
      url: Api.ReadRoles,
      params,
    },
    {
      errorMessageMode: mode,
    },
  );
}
// #endregion
// #region 读取角色功能信息
/**
 * 读取角色功能信息
 * @param roleId 角色ID
 * @param params 分页请求
 * @param mode 错误消息模型
 */
export function readRoleFunctions(roleId: bigint | string, params: PageRequest, mode: ErrorMessageMode = 'message') {
  return request.post<PageData<FunctionOutputDtoSimple>>(
    {
      url: `${Api.ReadFunctions}?roleId=${roleId}`,
      params,
    },
    {
      errorMessageMode: mode,
    },
  );
}
// #endregion
